package com.fare.taluo.ftp;

import org.apache.commons.configuration.PropertiesConfiguration;

/**
 * FTP服务提供者属性配置
 * @author xiangsf 2012-12-6
 *
 */
public class FtpConfiguration {

	public final static String FTP_SERVICE_TYPE = "ftp.service.type";
	public final static String FTP_SERVICE_HOST = "ftp.service.host";
	public final static String FTP_SERVICE_PORT = "ftp.service.port";
	public final static String FTP_SERVICE_USERNAME = "ftp.service.username";
	public final static String FTP_SERVICE_PASSWORD = "ftp.service.password";
	public final static String FTP_SERVICE_REMOTEDIR = "ftp.service.remotedir";
	public final static String FTP_SERVICE_LOCALDIR = "ftp.service.localdir";
	public final static String FTP_SERVICE_LOCALCHARSET = "ftp.service.localcharset";
	public final static String FTP_SERVICE_REMOTECHARSET = "ftp.service.remotecharset";
	/**
	 * ftp类型
	 */
	private String ftpType;
	/**
	 * ftp服务主机IP地址
	 */
	private String ftpHost;
	/**
	 * ftp服务主机开放ftp的端口号
	 */
	private int ftpPort;
	/**
	 * 登陆ftp服务主机的用户名
	 */
	private String username;
	/**
	 * 登陆ftp服务主机的密码
	 */
	private String password;
	/**
	 * 登陆ftp服务主机后的远程根目录
	 */
	private String remotedir;
	/**
	 * 本地目录
	 */
	private String localdir;
	/**
	 * 远程服务器的字符集设置
	 */
	private String defaultRemoteCharset;
	/**
	 * 本地的字符集设置
	 */
	private String defaultLocalCharset;
	
	public FtpConfiguration(){}
	
	public FtpConfiguration(String ftpType,String ftpHost, int ftpPort, String username,
			String password,String localdir, String remotedir, String remoteCharset, String localCharset) {
		super();
		this.ftpType = ftpType;
		this.ftpHost = ftpHost;
		this.ftpPort = ftpPort;
		this.username = username;
		this.password = password;
		this.localdir = localdir;
		this.remotedir = remotedir;
		this.defaultLocalCharset = localCharset;
		this.defaultRemoteCharset = remoteCharset;
	}
	public FtpConfiguration(String ftpHost, int ftpPort, String username,
			String password,String localdir, String remotedir, String remoteCharset, String localCharset) {
		super();
		this.ftpType = "ftp";
		this.ftpHost = ftpHost;
		this.ftpPort = ftpPort;
		this.username = username;
		this.password = password;
		this.localdir = localdir;
		this.remotedir = remotedir;
		this.defaultLocalCharset = localCharset;
		this.defaultRemoteCharset = remoteCharset;
	}
	public FtpConfiguration(String ip, PropertiesConfiguration propConfig){
		this.ftpHost = ip;
		this.ftpType = propConfig.getString(FTP_SERVICE_TYPE+"."+ip);
		this.ftpPort = propConfig.getInt(FTP_SERVICE_PORT+"."+ip, 21);
		this.username = propConfig.getString(FTP_SERVICE_USERNAME+"."+ip);
		this.password = propConfig.getString(FTP_SERVICE_PASSWORD+"."+ip);
		this.remotedir = propConfig.getString(FTP_SERVICE_REMOTEDIR+"."+ip);
		this.localdir = propConfig.getString(FTP_SERVICE_LOCALDIR+"."+ip);
		this.defaultLocalCharset = propConfig.getString(FTP_SERVICE_LOCALCHARSET+"."+ip, "iso-8859-1");
		this.defaultRemoteCharset = propConfig.getString(FTP_SERVICE_REMOTECHARSET+"."+ip, "GBK");
	}
	public String getFtpHost() {
		return ftpHost;
	}
	public void setFtpHost(String ftpHost) {
		this.ftpHost = ftpHost;
	}
	public int getFtpPort() {
		return ftpPort;
	}
	public void setFtpPort(int ftpPort) {
		this.ftpPort = ftpPort;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getRemotedir() {
		return remotedir;
	}
	public void setRemotedir(String remotedir) {
		this.remotedir = remotedir;
	}
	
	public String getLocaldir() {
		return localdir;
	}

	public void setLocaldir(String localdir) {
		this.localdir = localdir;
	}

	public String getDefaultRemoteCharset() {
		return defaultRemoteCharset;
	}

	public void setDefaultRemoteCharset(String defaultRemoteCharset) {
		this.defaultRemoteCharset = defaultRemoteCharset;
	}

	public String getDefaultLocalCharset() {
		return defaultLocalCharset;
	}

	public void setDefaultLocalCharset(String defaultLocalCharset) {
		this.defaultLocalCharset = defaultLocalCharset;
	}

	public String getFtpType() {
		return ftpType;
	}

	public void setFtpType(String ftpType) {
		this.ftpType = ftpType;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("FtpConfiguration [ftpHost=");
		builder.append(ftpHost);
		builder.append(", ftpType=");
		builder.append(ftpType);
		builder.append(", ftpPort=");
		builder.append(ftpPort);
		builder.append(", username=");
		builder.append(username);
		builder.append(", password=");
		builder.append(password);
		builder.append(", remotedir=");
		builder.append(remotedir);
		builder.append(", localdir=");
		builder.append(localdir);
		builder.append(", defaultRemoteCharset=");
		builder.append(defaultRemoteCharset);
		builder.append(", defaultLocalCharset=");
		builder.append(defaultLocalCharset);
		builder.append("]");
		return builder.toString();
	}

}
